/*
 * JsonrpcInterface.cpp
 *
 *  Created on: Apr 21, 2017
 *      Author: zhangjf
 */

#include <map>
#include <string>
#include <Poco/Dynamic/Var.h>
#include <Poco/Util/Application.h>

using namespace Poco::Dynamic;
using namespace Poco::Util;

#include "JsonrpcInterface.h"
#include <JsonrpcGetCellTypeList.h>
#include "JsonrpcGetAppList.h"
#include "JsonrpcGetAppProperties.h"

namespace network
{

std::map<std::string, std::function<JsonrpcInterface::Ptr(Object::Ptr&)>> JsonrpcInterfaceFactory::mapJRI;

JsonrpcInterface::JsonrpcInterface(const std::string& strMethod, Object::Ptr& joParams)
: _strMethod(strMethod)
, _joParams(joParams)
, _joResult()
, _joError()
{
	// TODO Auto-generated constructor stub

}

JsonrpcInterface::~JsonrpcInterface()
{
	// TODO Auto-generated destructor stub
}

JsonrpcInterface::Ptr JsonrpcInterfaceFactory::createInterface(std::string& interface, Object::Ptr& joParams)
{
	if (mapJRI.size() == 0)
	{
		initialize();
	}

	return mapJRI[interface](joParams);
}

void JsonrpcInterfaceFactory::initialize()
{
	mapJRI["GetCellTypeList"] = [](Object::Ptr& joParams){ return JsonrpcInterface::Ptr(new JsonrpcGetCellTypeList(joParams)); };
	mapJRI["GetAppList"] = [](Object::Ptr& joParams){ return JsonrpcInterface::Ptr(new JsonrpcGetAppList(joParams)); };
	mapJRI["GetAppProperties"] = [](Object::Ptr& joParams){ return JsonrpcInterface::Ptr(new JsonrpcGetAppProperties(joParams)); };
}

} /* namespace network */
